package com.sxpcwlkj.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sxpcwlkj.common.code.controller.BaseController;
import com.sxpcwlkj.system.entity.SysDept;
import com.sxpcwlkj.system.entity.bo.SysDeptBo;
import com.sxpcwlkj.system.entity.vo.SysDeptVo;
import com.sxpcwlkj.system.entity.vo.SysUserVo;
import com.sxpcwlkj.system.service.SysDeptService;
import com.sxpcwlkj.common.utils.AjaxResult;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName SysDeptController
 * @Description 部门
 * @Author 西决
 * @Date 2022/12/4 0:38
 */

@RequestMapping("system/dept")
@RestController
@RequiredArgsConstructor
public class SysDeptController extends BaseController {

    private final SysDeptService baseService;

    /**
     * 部门多级下拉菜单
     *
     * @return
     */
    @GetMapping("queryTree")
    public AjaxResult<List<SysDeptVo>> queryTree() {
        return success(baseService.queryTree());
    }
    /**
     * 部门多级下拉菜单
     * 全部包括关闭的状态
     * @return
     */
    @GetMapping("queryTreeAll")
    public AjaxResult<List<SysDeptVo>> queryTreeAll() {
        return success(baseService.queryTreeAll());
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @SaCheckPermission("system:user:query")
    @GetMapping("/{id}")
    public AjaxResult<SysDeptVo> queryById(@PathVariable Long id) {
        return success(baseService.queryById(id));
    }



    /**
     * 新增数据
     *
     * @param bo 实例对象
     * @return 实例对象
     */
    @SaCheckPermission("system:user:insert")
    @PostMapping
    public AjaxResult<Boolean> insert(@Validated @RequestBody(required = false) SysDeptBo bo) {
        return AjaxResult.success(baseService.insert(bo));
    }

    /**
     * 更新数据
     *
     * @param bo 实例对象
     * @return 实例对象
     */
    @SaCheckPermission("system:user:edit")
    @PutMapping
    public AjaxResult<Boolean> edit(@Validated @RequestBody(required = false) SysDeptBo bo) {
        return AjaxResult.success(baseService.update(bo));
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @SaCheckPermission("system:user:delete")
    @DeleteMapping("/{id}")
    public AjaxResult<Boolean> delete(@PathVariable Long id) {
        return AjaxResult.success(baseService.deleteById(id));
    }
}
